package com.thread;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TestThreadPool {

	
	public static void main(String[] args) throws InterruptedException {
		 //创建一个可重用固定线程数的线程池

        ExecutorService pool =Executors.newSingleThreadExecutor();
        
        Executors.newCachedThreadPool();
        Executors.newFixedThreadPool(10);
        Executors.newScheduledThreadPool(10);
        
        Thread t1 = new MyThread(1);

        Thread t2 = new MyThread(2);

        Thread t3 = new MyThread(3);

        Thread t4 = new MyThread(4);

        Thread t5 = new MyThread(5);
        
        //将线程放入池中进行执行
        pool.submit(t1);

        pool.submit(t2);
        
//        pool.execute(t3);
//
//        pool.execute(t4);
//
//        pool.execute(t5);
        
        System.out.println("put over");
       
        //打断
       t2.interrupt();
        
        pool.shutdown();
        
        
	}
	

}
class MyThread extends Thread {

	private int i;
	
	public MyThread(int i){
		this.i = i;
	}
	
	
    @Override

    public void run() {
    	while (!Thread.interrupted()) {

    		System.out.println(i+" = "+Thread.currentThread().isInterrupted());
    		System.out.println(i + "正在执行。。。");
            try {
    			sleep(3000);
    			interrupt();
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		}
    	System.out.println(i + "结束。。。");
        

    }
}